﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TasksModel
{
    public class TaskSerializer<T> where T : class
    {
        public string Serialize(T tl)
        {
            System.Xml.Serialization.XmlSerializer xs =
                new System.Xml.Serialization.XmlSerializer(typeof(T), "tasks");
            using (System.IO.StringWriter sw = new System.IO.StringWriter())
            {
                xs.Serialize(sw, tl);
                return sw.ToString();
            }
        }

        public T Deserialize(string xml)
        {
            System.Xml.Serialization.XmlSerializer xs =
                new System.Xml.Serialization.XmlSerializer(typeof(T), "tasks");
            using (System.IO.StringReader sw = new System.IO.StringReader(xml))
            {
                return xs.Deserialize(sw) as T;
            }
        }

        public T Deserialize(System.IO.TextReader tr)
        {
            System.Xml.Serialization.XmlSerializer xs =
                new System.Xml.Serialization.XmlSerializer(typeof(T), "tasks");
            return xs.Deserialize(tr) as T;
        }
    }
}